import requests
from lxml import etree
import pandas as pd

url="https://www.jkl.com.cn/shop.aspx"
UA="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0"

html=requests.get(url=url,headers={'User-Agent':UA}).text

response=etree.HTML(html)

urls=response.xpath("//div[@class='infoLis']/ul/li/a/@href")

all_data=pd.DataFrame()
for url in urls:

    city_url="https://www.jkl.com.cn/"+url
    city_html=requests.get(url=city_url,headers={'User-Agent':UA}).text
    response=etree.HTML(city_html)
    name=response.xpath("//span[@class='con01']/text()")
    local = response.xpath("//span[@class='con02']/text()")
    phone = response.xpath("//span[@class='con03']/text()")
    time = response.xpath("//span[@class='con04']/text()")

    data=pd.DataFrame(
        {
            "店名":name,
            "地点":local,
            "电话":phone,
            "营业时间":time
        }
    )
    all_data=pd.concat([all_data,data],ignore_index=True)
all_data.to_csv(
    "./file/店铺信息.csv",
    index=False,
    encoding="utf-8-sig"
)
